package o;

import com.google.android.exoplayer2.Format;
import com.google.android.exoplayer2.audio.Ac3Util;
import com.google.android.exoplayer2.audio.Ac3Util.SyncFrameInfo;
import com.google.android.exoplayer2.extractor.ts.TsPayloadReader.a;
import com.huawei.hms.framework.network.restclient.hwhttp.dns.DnsConfig;

public final class aga implements agc {
    private long ʻ;
    private boolean ʼ;
    private Format ʽ;
    private final String ˊ;
    private long ˊॱ;
    private aef ˋ;
    private int ˋॱ;
    private final anc ˎ;
    private final ane ˏ;
    private String ॱ;
    private int ॱॱ;
    private int ᐝ;

    public aga() {
        this(null);
    }

    public aga(String str) {
        this.ˏ = new ane(new byte[DnsConfig.MAX_CACHE_ENTRIES]);
        this.ˎ = new anc(this.ˏ.ˎ);
        this.ॱॱ = 0;
        this.ˊ = str;
    }

    public void ˏ() {
        this.ॱॱ = 0;
        this.ᐝ = 0;
        this.ʼ = false;
    }

    public void ˏ(ady o_ady, a aVar) {
        aVar.ˊ();
        this.ॱ = aVar.ˎ();
        this.ˋ = o_ady.ˊ(aVar.ˏ(), 1);
    }

    public void ˋ(long j, int i) {
        this.ˊॱ = j;
    }

    public void ˊ(anc o_anc) {
        while (o_anc.ˊ() > 0) {
            switch (this.ॱॱ) {
                case 0:
                    if (!ॱ(o_anc)) {
                        break;
                    }
                    this.ॱॱ = 1;
                    this.ˎ.ˏ[0] = (byte) 11;
                    this.ˎ.ˏ[1] = (byte) 119;
                    this.ᐝ = 2;
                    break;
                case 1:
                    if (!ˋ(o_anc, this.ˎ.ˏ, DnsConfig.MAX_CACHE_ENTRIES)) {
                        break;
                    }
                    ˊ();
                    this.ˎ.ˋ(0);
                    this.ˋ.ˎ(this.ˎ, DnsConfig.MAX_CACHE_ENTRIES);
                    this.ॱॱ = 2;
                    break;
                case 2:
                    int min = Math.min(o_anc.ˊ(), this.ˋॱ - this.ᐝ);
                    this.ˋ.ˎ(o_anc, min);
                    this.ᐝ = min + this.ᐝ;
                    if (this.ᐝ != this.ˋॱ) {
                        break;
                    }
                    this.ˋ.ˋ(this.ˊॱ, 1, this.ˋॱ, 0, null);
                    this.ˊॱ += this.ʻ;
                    this.ॱॱ = 0;
                    break;
                default:
                    break;
            }
        }
    }

    public void ˋ() {
    }

    private boolean ˋ(anc o_anc, byte[] bArr, int i) {
        int min = Math.min(o_anc.ˊ(), i - this.ᐝ);
        o_anc.ˎ(bArr, this.ᐝ, min);
        this.ᐝ = min + this.ᐝ;
        return this.ᐝ == i;
    }

    private boolean ॱ(anc o_anc) {
        while (o_anc.ˊ() > 0) {
            if (this.ʼ) {
                int ʽ = o_anc.ʽ();
                if (ʽ == 119) {
                    this.ʼ = false;
                    return true;
                }
                this.ʼ = ʽ == 11;
            } else {
                this.ʼ = o_anc.ʽ() == 11;
            }
        }
        return false;
    }

    private void ˊ() {
        this.ˏ.ˋ(0);
        SyncFrameInfo ˊ = Ac3Util.ˊ(this.ˏ);
        if (!(this.ʽ != null && ˊ.ˏ == this.ʽ.ॱˎ && ˊ.ˎ == this.ʽ.ʼॱ && ˊ.ˊ == this.ʽ.ʽ)) {
            this.ʽ = Format.ˎ(this.ॱ, ˊ.ˊ, null, -1, -1, ˊ.ˏ, ˊ.ˎ, null, null, 0, this.ˊ);
            this.ˋ.ˎ(this.ʽ);
        }
        this.ˋॱ = ˊ.ॱ;
        this.ʻ = (1000000 * ((long) ˊ.ʼ)) / ((long) this.ʽ.ʼॱ);
    }
}
